package edu.hunau.demo;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author hb
 * @date 2022-11-29 17:25:24
 */
public class MyHander implements InvocationHandler {
    private Object target;

    public MyHander(Object target){
        this.target=target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //额外功能
        TxManager txManager = new TxManager();
        txManager.begin();
        //执行目标对象的目标方法
        Object result = method.invoke(target, args);
        txManager.commit();

        return result;
    }
}
